package controller.link;

import view.client.Console;
import model.Hearer;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import controller.Link;
import model.User;
import model.Attendant;
import model.Server;

public class Yell implements Link, Serializable {

    private String whoSaid;
    private String message;

    public Yell(String msg) {
        this.message = msg;
    }

    public Yell(String whoSaid, String msg) {
        this.whoSaid = whoSaid;
        this.message = msg;
    }

    public Yell(Hearer h, String msg) {
        whoSaid = h.getName();
        this.message = msg;
        h.send((Link) this);
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        User user = at.getUser();
        this.whoSaid = user.getName();
        try {
            server.sendToAll((Link) this);
        } catch (Exception ex) {
            Logger.getLogger(Yell.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void clientUse(Console console) {
        console.getTxtArea().append(whoSaid + ": " + message + "\n");
    }
}
